*ALTERNATIVE INDEPENDENT VARIABLE

*This will print tables in stata output, discussed (not reported) in SI B.2.2

clear all
use "ESS.dta" 

gen EE2= Education


gen D=D_race
gen PD=PD_race
 label var D "Discriminatory attitudes"
 label var PD "Perceived discrimination"

 
 global y1 "D"
 global y2 "PD" 
 global x1 "Education"
 global z1 "Age Female Edu_mum  i.Country  i.essround"
 global z2 "Female  Edu_mum i.Country  i.essround"
 global IV "T r"
 global z1b "Age Age2 Female Edu_mum Africa Asia Muslim Jew i.Country  i.essround"
 global z2b "Female  Edu_mum i.Country Africa Asia Muslim Jew  i.essround"

 

local  CountryFE
local  TimeFE   
local  Sociodemographics
local  Estimator   


quietly: reg  $y1   $x1  
est store Correlation
estadd local CountryFE "No"
estadd local TimeFE "No"
estadd local  Sociodemographics "No"
estadd local  Estimator "OLS"  
 
quietly: reg  $y1   $x1  $z1  if Monotonic==1, robust
est store OLS
estadd local CountryFE "Yes"
estadd local TimeFE "Yes"
estadd local  Sociodemographics "Yes"
estadd local  Estimator "OLS"

quietly:rdbwselect  $y1  r if Monotonic==1,  covs(Edu_mum Female r1 r2 r3 r4 r5 r6 r7 r8 c1  c2 c3 c4 c5 c6 c7 c8 c9 c10 c11 c12 c13 c14 c15 c16 c17 c18 c19 c20 c21 c22 c23 c24 )
local u1 =floor(e(h_mserd))
g  w=max(0,`u1'-abs(r)) 

quietly:   ivreg2  $y1  ($x1 = $IV)   $z2 [pweight= w] if Monotonic==1, first  savefirst savefprefix(fs_1) baselevels robust   gmm2s 
est store IV_all
mat l e(first)
local Fm= floor(e(first)[rownumb(e(first),"SWF"),1])
local N3=  e(N)
su  $y1 if e(sample), mean
loc Meanm:di%8.2fc r(mean)
drop w
estadd local CountryFE "Yes"
estadd local TimeFE "Yes"
estadd local  Sociodemographics "Yes"
estadd local  Estimator "GMM"

quietly: rdbwselect  $y1  r if Strong==1,  covs(Edu_mum Female  r1 r2 r3 r4 r5 r6 r7 r8 c1  c2 c3 c4 c5 c6 c7 c8 c9 c10   c10 c11 c12 c13 c14 c15 c16 c17 c18 c19 c20 c21 c22 c23 c24 )
local u2 =floor(e(h_mserd))
g w=max(0,`u2'-abs(r)) 

quietly: ivreg2  $y1  ($x1 = $IV)   $z2  [pweight=w] if Strong==1, first  baselevels robust   gmm2s   savefirst savefprefix(fs_2)
est store IV_restricted
mat l e(first)
local Fs= floor(e(first)[rownumb(e(first),"SWF"),1])
local N4= e(N)
su  $y1 if e(sample), mean
loc Mean:di%8.2fc r(mean)
loc Means=trim("`Mean'")
drop w
estadd local CountryFE "Yes"
estadd local TimeFE "Yes"
estadd local  Sociodemographics "Yes"
estadd local  Estimator "GMM"

esttab  Correlation OLS     IV_all  IV_restricted, replace se star(* 0.1 ** 0.05 *** 0.01) obslast collabels(, none)   wrap  legend  gaps nolz  booktabs mlabel("Corr" "OLS"  "IV (all)"  "IV (strong)")  nonumbers  cells(b(star fmt(3)  ) se(fmt(3) par  )) compress label title(Ethnoracial attitudes, alternative IV.)   drop(Female Age   Edu_mum   _cons *.Country  *.essround)      stats(  CountryFE  TimeFE Sociodemographics   Estimator N r2  widstat  , fmt(a1 a2 a3   a5 %9.0fc  2 %9.0fc  1  )  labels( `"Country FE"'  `"Time FE"' `"Sociodemographics"'   `"Estimator"' `"N.obs"' `"\(R^{2}\)"'  `"\(F\)-statistics"'   ) ) 
 
*****PERCEIVED DISCRIMINATION***********************************************************************


clear all
use "ESS.dta" 


gen D=D_race
gen PD=PD_race
 label var D "Discriminatory attitudes"
 label var PD "Perceived discrimination"

 
 global y1 "D"
 global y2 "PD" 
 global x1 "Education"
 global z1 "Age Female Edu_mum  i.Country  i.essround"
 global z2 "Female  Edu_mum i.Country  i.essround"
 global z1b "Age Age2 Female Edu_mum Africa Asia Muslim Jew i.Country  i.essround"
 global z2b "Female  Edu_mum i.Country Africa Asia Muslim Jew  i.essround"
*********************************************************************************************************


*PERCEIVED DISCRIMINATION
 
la var total_eduyrs "Years of education"

local  CountryFE
local  TimeFE   
local  Sociodemographics
local  Estimator   

quietly: reg $y2  $x1  
est store Correlation
estadd local CountryFE "No"
estadd local TimeFE "No"
estadd local  Sociodemographics "No"
estadd local  Estimator "OLS"

quietly:  reg $y2 $x1 $z2b if  Monotonic==1, robust
est store OLS
estadd local CountryFE "Yes"
estadd local TimeFE "Yes"
estadd local  Sociodemographics "Yes"
estadd local  Estimator "OLS"
 
 
quietly:  rdbwselect  $y2  r if Monotonic==1,    covs(Edu_mum Female Africa Asia Muslim Jew r1 r2 r3 r4 r5 r6 r7 r8 c1  c2 c3 c4 c5 c6 c7 c8 c9 c10   c10 c11 c12 c13 c14 c15 c16 c17 c18 c19 c20 c21 c22 c23 c24 )
local u1 =floor(e(h_mserd))
g w=max(0,`u1'-abs(r)) 


quietly:  ivreg2 $y2  ($x1 = $IV) $z2b  [pweight=w]  if Monotonic==1, first   savefirst savefprefix(fs_1) baselevels robust gmm2s 
est store IV_all
mat l e(first)
local Fm= floor(e(first)[rownumb(e(first),"SWF"),1])
local N3=  e(N)
su  $y2 if e(sample), mean
loc Mean:di%8.2fc r(mean)
loc Meanm=trim("`Mean'")
drop w
estadd local CountryFE "Yes"
estadd local TimeFE "Yes"
estadd local  Sociodemographics "Yes"
estadd local  Estimator "GMM"

quietly:  rdbwselect  $y2  r if Strong==1,    covs(Edu_mum Female Africa Asia Muslim Jew r1 r2 r3 r4 r5 r6 r7 r8 c1  c2 c3 c4 c5 c6 c7 c8 c9 c10   c10 c11 c12 c13 c14 c15 c16 c17 c18 c19 c20 c21 c22 c23 c24 )
local u2 =floor(e(h_mserd))
g w=max(0,`u2'-abs(r)) 

quietly: ivreg2 $y2  ($x1 = $IV)  $z2b  [pweight=w]  if Strong==1, first   savefirst savefprefix(fs_2) baselevels robust   gmm2s  
est store IV_restricted
mat l e(first)
local Fs= floor(e(first)[rownumb(e(first),"SWF"),1])
local N4= e(N)
su  $y2 if e(sample), mean
loc Mean:di%8.2fc r(mean)
loc Means=trim("`Mean'")
drop w
estadd local CountryFE "Yes"
estadd local TimeFE "Yes"
estadd local  Sociodemographics "Yes"
estadd local  Estimator "GMM"

 

esttab  Correlation OLS   IV_all  IV_restricted, replace se star(* 0.1 ** 0.05 *** 0.01) obslast collabels(, none)   wrap  legend  gaps nolz  booktabs mlabel("Corr" "OLS" "IV (all)"  "IV (strong)")  nonumbers  cells(b(star fmt(3)  ) se(fmt(3) par  )) compress label title(Perceived ethnoracial discrimination, alternative IV.)   drop(Female     Edu_mum Asia Muslim Africa   _cons *.Country  *.essround)       stats(  CountryFE  TimeFE Sociodemographics   Estimator N r2  widstat  , fmt(a1 a2 a3   a5 %9.0fc  2 %9.0fc  1  )  labels( `"Country FE"'  `"Time FE"' `"Sociodemographics"'   `"Estimator"' `"N.obs"' `"\(R^{2}\)"'  `"\(F\)-statistics"'   ) ) 



*******GENDER

clear all
use "ESS.dta" 

gen D=D_gender
gen PD=PD_gender
 label var D "Discriminatory attitudes"
 label var PD "Perceived discrimination"

 
 global y1 "D"
 global y2 "PD" 
 global x1 "Education"
 global z1 "Age Age2  Edu_mum i.Country  i.essround"
 global z2 "Edu_mum i.Country  i.essround"

local  CountryFE
local  TimeFE   
local  Sociodemographics
local  Estimator   


quietly: reg  $y1   $x1  
est store Correlation
estadd local CountryFE "No"
estadd local TimeFE "No"
estadd local  Sociodemographics "No"
estadd local  Estimator "OLS"  
 
quietly: reg  $y1   $x1  $z1  if Monotonic==1, robust
est store OLS
estadd local CountryFE "Yes"
estadd local TimeFE "Yes"
estadd local  Sociodemographics "Yes"
estadd local  Estimator "OLS"

quietly: rdbwselect  $y1  r if Monotonic==1,  covs(Edu_mum   r1 r2 r3 r4 r5 r6 r7 r8 c1 c2 c3 c4 c5 c6 c7 c8 c9  c10 c11 c12 c13 c14 c15 c16 c17 c18 c19 c20 c21 c22 c23 c24 )
local u1 =floor(e(h_mserd))
g  w=max(0,`u1'-abs(r)) 


quietly:  ivreg2  $y1  ($x1 = $IV)   $z2 [pweight= w] if Monotonic==1, first  savefirst savefprefix(fs_1) baselevels robust   gmm2s 
est store IV_all
mat l e(first)
local Fm= floor(e(first)[rownumb(e(first),"SWF"),1])
local N3=  e(N)
su  $y1 if e(sample), mean
loc Meanm:di%8.2fc r(mean)
drop w
estadd local CountryFE "Yes"
estadd local TimeFE "Yes"
estadd local  Sociodemographics "Yes"
estadd local  Estimator "GMM"

quietly: rdbwselect  $y1  r if Strong==1,  covs(Edu_mum    r1 r2 r3 r4 r5 r6 r7 r8 c1 c2 c3 c4 c5 c6 c7 c8 c9 c10 c11 c12 c13 c14 c15 c16 c17 c18 c19 c20 c21 c22 c23 c24 )
local u2 =floor(e(h_mserd))
g w=max(0,`u2'-abs(r)) 

quietly: ivreg2  $y1  ($x1 = $IV)   $z2  [pweight=w] if Strong==1, first  baselevels robust   gmm2s   savefirst savefprefix(fs_2)
est store IV_restricted
mat l e(first)
local Fs= floor(e(first)[rownumb(e(first),"SWF"),1])
local N4= e(N)
su  $y1 if e(sample), mean
loc Mean:di%8.2fc r(mean)
loc Means=trim("`Mean'")
drop w
estadd local CountryFE "Yes"
estadd local TimeFE "Yes"
estadd local  Sociodemographics "Yes"
estadd local  Estimator "GMM"

esttab  Correlation OLS     IV_all  IV_restricted, replace se star(* 0.1 ** 0.05 *** 0.01) obslast collabels(, none)   wrap  legend  gaps nolz  booktabs mlabel("Corr" "OLS"  "IV (all)"  "IV (strong)")  nonumbers  cells(b(star fmt(3)  ) se(fmt(3) par  )) compress label title(Discriminatory gender attitudes, , alternative IV.)   drop(  Age   Edu_mum   _cons *.Country  *.essround)      stats(  CountryFE  TimeFE Sociodemographics   Estimator N r2  widstat  , fmt(a1 a2 a3   a5 %9.0fc  2 %9.0fc  1  )  labels( `"Country FE"'  `"Time FE"' `"Sociodemographics"'   `"Estimator"' `"N.obs"' `"\(R^{2}\)"'  `"\(F\-statistics)"'   ) ) 
 
*****PERCEIVED DISCRIMINATION***********************************************************************


clear all
use "ESS.dta" 

la var total_eduyrs "Highest diploma"
global x1 "Education"


gen D=D_gender
gen PD=PD_gender
 label var D "Discriminatory attitudes"
 label var PD "Perceived discrimination"

 
 global y1 "D"
 global y2 "PD" 
 global z1 "Age   Edu_mum  i.Country  i.essround"
 global z2 "Edu_mum i.Country  i.essround"
 

 
*********************************************************************************************************


*PERCEIVED DISCRIMINATION
 

local  CountryFE
local  TimeFE   
local  Sociodemographics
local  Estimator   

quietly: reg $y2  $x1  
est store Correlation
estadd local CountryFE "No"
estadd local TimeFE "No"
estadd local  Sociodemographics "No"
estadd local  Estimator "OLS"

quietly:  reg $y2 $x1 $z2 if  Monotonic==1, robust
est store OLS
estadd local CountryFE "Yes"
estadd local TimeFE "Yes"
estadd local  Sociodemographics "Yes"
estadd local  Estimator "OLS"
 
 
quietly:  rdbwselect  $y2  r if Monotonic==1,    covs(Edu_mum   r1 r2 r3 r4 r5 r6 r7 r8 c1 c2 c3 c4 c5 c6 c7 c8 c9 c10 c11 c12 c13 c14 c15 c16 c17 c18 c19 c20 c21 c22 c23 c24 )
local u1 =floor(e(h_mserd))
g w=max(0,`u1'-abs(r)) 


quietly:  ivreg2 $y2  ($x1 = $IV) $z2  [pweight=w]  if Monotonic==1, first   savefirst savefprefix(fs_1) baselevels robust gmm2s 
est store IV_all  
mat l e(first)
local Fm= floor(e(first)[rownumb(e(first),"SWF"),1])
local N3=  e(N)
su  $y2 if e(sample), mean
loc Mean:di%8.2fc r(mean)
loc Meanm=trim("`Mean'")
drop w
estadd local CountryFE "Yes"
estadd local TimeFE "Yes"
estadd local  Sociodemographics "Yes"
estadd local  Estimator "GMM"

quietly:  rdbwselect  $y2  r if Strong==1,    covs(Edu_mum   r1 r2 r3 r4 r5 r6 r7 r8 c1   c2 c3 c4 c5 c6 c7 c8 c9 c10 c11 c12 c13 c14 c15 c16 c17 c18 c19 c20 c21 c22 c23 c24 )
local u2 =floor(e(h_mserd))
g w=max(0,`u2'-abs(r)) 

quietly: ivreg2 $y2  ($x1 = $IV)  $z2  [pweight=w]  if Strong==1, first   savefirst savefprefix(fs_2) baselevels robust   gmm2s  
est store  IV_restricted
mat l e(first)
local Fs= floor(e(first)[rownumb(e(first),"SWF"),1])
local N4= e(N)
su  $y2 if e(sample), mean
loc Mean:di%8.2fc r(mean)
loc Means=trim("`Mean'")
drop w
estadd local CountryFE "Yes"
estadd local TimeFE "Yes"
estadd local  Sociodemographics "Yes"
estadd local  Estimator "GMM"

 
esttab  Correlation OLS   IV_all  IV_restricted, replace se star(* 0.1 ** 0.05 *** 0.01) obslast collabels(, none)   wrap  legend  gaps nolz  booktabs mlabel("Corr" "OLS" "IV (all)"  "IV (strong)")  nonumbers  cells(b(star fmt(3)  ) se(fmt(3) par  )) compress label title(Perceived gender discrimination, alternative IV.)   drop(      Edu_mum    _cons *.Country  *.essround)       stats(  CountryFE  TimeFE Sociodemographics   Estimator N r2  widstat  , fmt(a1 a2 a3   a5 %9.0fc  2 %9.0fc  1  )  labels( `"Country FE"'  `"Time FE"' `"Sociodemographics"'   `"Estimator"' `"N.obs"' `"\(R^{2}\)"'  `"\(F\)-statistics"'   ) ) 


